/**
 * 
 */
package com.google.code.cisx.converters;

import com.google.code.cisx.client.dto.ProjectDependencyViewHelper;
import com.google.code.cisx.model.project.ProjectDependency;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;

import java.util.Map;

/**
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @since 1.0
 * @version $Id: ProjectDependencyConverter.java 113 2008-01-12 05:58:36Z
 *          rahul.thakur.xdev $
 */
public class ProjectDependencyConverter extends CommonConverter implements Converter {

  /**
   * 
   */
  public ProjectDependencyConverter() {
    super();
  }

  /**
   * @param bub
   */
  public ProjectDependencyConverter(BeanUtilsBeanExtended bub) {
    super(bub);

  }

  /**
   * {@inheritDoc}
   * 
   * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class,
   *      java.lang.Object)
   */
  public Object convert(Class type, Object value) {
    Object retValue = null;
    try {
      Map description = beanUtilsBean.describe(value);
      if (type == ProjectDependency.class)
        retValue = new ProjectDependencyViewHelper();
      else if (type == ProjectDependencyViewHelper.class)
        retValue = new ProjectDependency();
      beanUtilsBean.populate(retValue, description);
    } catch (Exception e) {
      throw new ConversionException(e);
    }
    return retValue;
  }
}
